<cfset ID = #client.chapa#>
<cfset APPROVED = "N">
<cfif IsDefined("url.DocNo")>
    <CFQUERY NAME="qryOriginator" DATASOURCE="#client.company_dsn#">
        SELECT PERSONNELIDNO,APPROVED
        FROM ECIN21MAINUPDATE
        WHERE ROUTEID = '#url.DocNo#'
    </cfquery>
    <cfset ID = #qryOriginator.personnelidno#>
    <cfset APPROVED = #qryOriginator.APPROVED#>
</cfif>

<cfif #ID# eq #client.chapa# and APPROVED neq "Y">
    For more details and actions, Please see 201 Updating Form 
<a href ="http://filinvestihcm.imachinecloud.com/etasks/applications/main/index.cfm?taskid=4EEB50D1-9A5C-B24F-F4D753F7491AC251&desc=e201%20Updating%20Form&paramappid=%29%27%5D%3F%3ECN%5E%28GI%22_&paramsubcompany=%218P%20%20&paramopennewwindow=%218P%20%20&params2=" target="new">here</a> 
</cfif>


<cfif #ID# neq #client.chapa# and APPROVED neq "Y">
<CFQUERY NAME="qryGET201TABLES" DATASOURCE = "#client.company_dsn#">
	SELECT ORIGTABLENAME, DESCRIPTION, MANYTOONE, PKCOLUMNS, RefTable
	FROM ECIN201TABLES
	ORDER BY SORTNUMBER
</CFQUERY>
<style type="text/css">
.style1 {
	color: #FF0000;
	font-weight: bold;
}
.style3 {
	color: #006600;
	font-weight: bold;
}
.style5 {
	color: #330099;
	font-weight: bold;
}
</style>

<div id="panel" STYLE ="background:grey;vertical-align:central; width:85%">
<cfoutput query = "qryGET201TABLES"> 

<h3>#description#</h3>
<table border=1 width="100%" bgcolor="FFFFFF">
  	<CFSET MY201ROW =  qryGET201TABLES.CURRENTROW>
    <cfset headerchange = 1>	
    <!---<tr>
    	<td colspan="4" bgcolor="##33CCFF"><div align="center"><b>#DESCRIPTION#</b></div></td>
    </tr>--->
    <cfquery name="GetFieldsOrig" datasource="#client.global_dsn#">
     	SELECT COLUMNNAME, COLUMNDESC, COLUMNTYPE, FIELDGROUP
      	FROM GRGBOSETABLEFIELDS 
      	WHERE
      		(TABLENAME  = '#RefTable#') AND
      		<!---(ISVISIBLEEFORM = 'Y' OR ISVISIBLEEFORM IS NULL) AND 01182010 by mico--->
      		(COLUMNNAME NOT IN ('RECDATECREATED','RECCREATEDBY','USERID',
      		'DATELASTUPDATE','TIMELASTUPDATE','ROUTEID','APPROVED','ISBATCHAPPROVE',
      		'DATEACTIONWASDONE','ROUTED','ACTIONBY','GUID','DOCNUMBER','PERSONNELIDNO',
		  	'PERSONNELBADGENO','ATTACHMENTCODE','RESERVEDBY'))
			AND COLUMNTYPE <> 'ftBlob'
     	ORDER BY COLUMNNAME
    </cfquery>
    <cfquery name="GetFieldsTEMP" datasource="#client.global_dsn#">
  		SELECT COLUMNNAME, COLUMNDESC, COLUMNTYPE, FIELDGROUP
      	FROM GRGBOSETABLEFIELDS 

      	WHERE
      		(TABLENAME  = 'E#RefTable#M') AND
      		<!---(ISVISIBLEEFORM = 'Y' OR ISVISIBLEEFORM IS NULL) AND by mico--->
      		(COLUMNNAME NOT IN ('RECDATECREATED','RECCREATEDBY','USERID',
      		'DATELASTUPDATE','TIMELASTUPDATE','ROUTEID','APPROVED','ISBATCHAPPROVE',
      		'DATEACTIONWASDONE','ROUTED','ACTIONBY','GUID','DOCNUMBER','PERSONNELIDNO',
      		'PERSONNELBADGENO','ATTACHMENTCODE'))
			AND COLUMNTYPE <> 'ftBlob'
      	ORDER BY COLUMNNAME
	</cfquery>
    <cfif MANYTOONE>
		<cfset lstPKCOLUMNS = #PKCOLUMNS#>
      	<cfquery name = "qryRETRIEVEORIG" datasource = "#client.company_dsn#" >
        	<!---SET CONCAT_NULL_YIELDS_NULL OFF--->
        	SELECT 
	        <cfloop from = "1" to = "#ListLen(lstPKCOLUMNS)#" index = "Counter">
			#ListGetAt(lstPKCOLUMNS, Counter)# AS 
          		<cfif COUNTER NEQ ListLen(lstPKCOLUMNS)>+</cfif>
        	</cfloop> 
        	PKCOLUMNVALUES,
        	<cfloop query = "GetFieldsOrig">
          		#COLUMNNAME#<cfif CURRENTROW NEQ RECORDCOUNT>,</cfif>
	        </cfloop>
        	FROM #RefTable#
        	WHERE GUID = '#GETENTRY.GUID#'
		</cfquery>
      	<cfquery name = "qryRETRIEVETEMP" datasource = "#client.company_dsn#" >
        	<!---SET CONCAT_NULL_YIELDS_NULL OFF--->
        	SELECT 
	        <cfloop from = "1" to = "#ListLen(lstPKCOLUMNS)#" index = "Counter">
    		    
			#ListGetAt(lstPKCOLUMNS, Counter)# AS 
          		<cfif COUNTER NEQ ListLen(lstPKCOLUMNS)>+</cfif>
        	</cfloop> 
	        PKCOLUMNVALUES,
    	    <cfloop query = "GetFieldsOrig">
        		#COLUMNNAME#<cfif CURRENTROW NEQ RECORDCOUNT>,</cfif>
	        </cfloop>
        	FROM E#RefTable#M
        	WHERE GUID = '#GETENTRY.GUID#'
			<cfif #qryGET201TABLES.manytoone# eq "1">
				AND DOCNUMBER = '#GETENTRY.DOCNUMBER#'
			</cfif>
		</cfquery>
      	<!---CHECK TO SEE IF THERE IS A DELETED RECORD FROM THE ORIGINAL--->
      	<cfloop query = "qryRETRIEVEORIG">
			<CFSET HEADERCHANGE = 1>
	  		<CFSET MYROW = CURRENTROW>
        	<cfset iA = qryRETRIEVEORIG.PKCOLUMNVALUES[CURRENTROW]>
			<CFSET lstRECVALUES = "">
        	<cfset DELETED = TRUE>
        	<cfloop query = "qryRETRIEVETEMP">
		   		<CFSET iB = qryRETRIEVETEMP.PKCOLUMNVALUES>
		   		<CFSET MYTEMPROW = qryRETRIEVETEMP.CURRENTROW>
          		<cfif iA EQ iB>
	        	<!---THE RECORD FROM THE ORIGINAL WAS FOUND. CHECK TO SEE IF THERE ARE CHANGES--->
            		<cfset DELETED = FALSE >	
              		<cfloop query = "GetFieldsOrig">
					<CFSET theorigstring = EVALUATE("qryRETRIEVEORIG.#COLUMNNAME#[MYROW]") >
					<CFSET thetempstring = EVALUATE(			"qryRETRIEVETEMP.#COLUMNNAME#[MYTEMPROW]")>
              		<cfif  TRIM(TOSTRING(theorigstring)) NEQ TRIM(TOSTRING(thetempstring)) >
                		<cfif HEADERCHANGE>
                  			<tr>
                    			<td colspan="3"><div align="center" class="style5">
                   			    CHANGES IN THE RECORD OF:
                    			    <cfloop from = "1" to = "#ListLen(lstPKCOLUMNS)#" index = "Counter">	
                    			    <CFQUERY NAME = "GETPKCOLUMNDESC" DBTYPE = "QUERY">
                   			        SELECT COLUMNDESC FROM GETFIELDSORIG
                    			      WHERE COLUMNNAME = '#ListGetAt(lstPKCOLUMNS, Counter)#'
                   			        </CFQUERY>
                    			    (#EVALUATE("GETPKCOLUMNDESC.COLUMNDESC")#)				  				
                    			    #EVALUATE("qryRETRIEVEORIG.#ListGetAt(lstPKCOLUMNS, 
                    			    Counter)#[MYROW]")#
                    			    <CFMODULE TEMPLATE = "show201lookup.cfm" MASTERTABLE = "#qryGET201TABLES.RefTable[MY201ROW]#" MASTERFIELD = "#ListGetAt(lstPKCOLUMNS, Counter)#" VALUETOLOOK = "#EVALUATE("qryRETRIEVEORIG.#ListGetAt(lstPKCOLUMNS,Counter)#[MYROW]")#">
                    			    #LOOKUPRESULT#
                    			    <cfif COUNTER NEQ ListLen(lstPKCOLUMNS)>
                    			      ,
                   			        </cfif>
                   			          </cfloop>                    
                  			  </div></td>
                  			</tr>
                  			<tr>
                    			<td width="25%"><div align="center">FIELD DESCRIPTION </div></td>
                    			<td width="15%"><div align="center">OLD VALUE </div></td>
                    			<td width="16%"><div align="center">NEW VALUE </div></td>
                  			</tr>
                		</cfif>
                	<cfset headerchange = 0 >
			<cfset bg = white>
                	<tr style="background-color:#bg#">
                  		
                  <cfif #EVALUATE("qryRETRIEVEORIG.#COLUMNNAME#[MYROW]")# NEQ "">
		    <td> #UCASE(GETFIELDSORIG.COLUMNDESC)# </td>
                    <td>#EVALUATE("qryRETRIEVEORIG.#COLUMNNAME#[MYROW]")#
					<CFMODULE TEMPLATE = "show201lookup.cfm" MASTERTABLE = "#qryGET201TABLES.RefTable[MY201ROW]#" MASTERFIELD = "#GETFIELDSORIG.COLUMNNAME#" VALUETOLOOK = "#EVALUATE("qryRETRIEVEORIG.#COLUMNNAME#[MYROW]")#">
					#LOOKUPRESULT#					</td>
                  </cfif>
                  <cfif #EVALUATE("qryRETRIEVETEMP.#COLUMNNAME#[MYTEMPROW]")# NEQ "">
                    <td width="6%"> #EVALUATE("qryRETRIEVETEMP.#COLUMNNAME#[MYTEMPROW]")#
					<CFMODULE TEMPLATE = "show201lookup.cfm" MASTERTABLE = "#qryGET201TABLES.RefTable[MY201ROW]#" MASTERFIELD = "#GETFIELDSORIG.COLUMNNAME#" VALUETOLOOK = "#EVALUATE("qryRETRIEVETEMP.#COLUMNNAME#[MYTEMPROW]")#">
					#LOOKUPRESULT#					</td>
                  </cfif>
                </tr>
              </cfif>
            </cfloop>
            <CFBREAK>
          </cfif>
        </cfloop>
        <cfif DELETED>
            <tr>
              <td colspan="3"><div align="center" class="style1">THE ORIGINATOR DELETED THE FOLLOWING RECORD: </div></td>
            </tr>
            <tr>
              <td><div align="center">FIELD DESCRIPTION</div></td>
              <td colspan="2"><div align="center">VALUE</div></td>
		    </tr>
			<CFLOOP QUERY = "GETFIELDSORIG">
				<TR>
					<TD> #UCASE(COLUMNDESC)# </TD>
					<TD colspan="2"> <CFIF #EVALUATE("QRYRETRIEVEORIG.#COLUMNNAME#[MYROW]")# NEQ "">
						#EVALUATE("QRYRETRIEVEORIG.#COLUMNNAME#[MYROW]")#
						<CFMODULE TEMPLATE = "show201lookup.cfm" MASTERTABLE = "#qryGET201TABLES.RefTable[MY201ROW]#" MASTERFIELD = "#GETFIELDSORIG.COLUMNNAME#" VALUETOLOOK = "#EVALUATE("QRYRETRIEVEORIG.#COLUMNNAME#[MYROW]")#">
						#LOOKUPRESULT#
						<CFELSE>
						&nbsp;
						</CFIF>					</TD>
				</TR>
			</CFLOOP>
        </cfif>
      </cfloop>
	  <CFLOOP QUERY = "qryRETRIEVETEMP">
	  	<CFSET MYROW = CURRENTROW>
	  	<cfset iA = qryRETRIEVETEMP.PKCOLUMNVALUES[MYROW]>
		<CFSET ADDED = TRUE>
		
	  	<CFLOOP QUERY = "qryRETRIEVEORIG">
			<CFSET MYORIGROW = qryRETRIEVEORIG.CURRENTROW>
			<CFSET iB = qryRETRIEVEORIG.PKCOLUMNVALUES>
			<CFIF iA EQ iB>
				<CFSET ADDED = FALSE>
			</CFIF>
		</CFLOOP>
		<CFIF ADDED>
			 <tr>
	      <br/><br/>
              <td colspan="3"><div align="center" class="style3">THE ORIGINATOR ADDED THE FOLLOWING RECORD: </div></td>
            </tr>
			 <tr>
              <td><div align="center">FIELD DESCRIPTION</div></td>
              <td><div align="center">VALUE</div></td>
		    </tr>
            <cfloop query = "GETFIELDSORIG">
              <tr>
                
				
                
		<CFIF #EVALUATE("QRYRETRIEVETEMP.#COLUMNNAME#[MYROW]")# NEQ "">
			<td>#UCASE(COLUMNDESC)#</td>
			<TD>#EVALUATE("QRYRETRIEVETEMP.#COLUMNNAME#[MYROW]")#
			
			<CFMODULE TEMPLATE = "show201lookup.cfm" MASTERTABLE = "#qryGET201TABLES.RefTable[MY201ROW]#" MASTERFIELD = "#GETFIELDSORIG.COLUMNNAME#" VALUETOLOOK = "#EVALUATE("QRYRETRIEVETEMP.#COLUMNNAME#[MYROW]")#">
						#LOOKUPRESULT#
			</TD>
			
		</CFIF>				
            </CFLOOP>
		</CFIF>
	  </cfloop>
      <cfelse>
      <cfquery name = "qryRETRIEVEORIG" datasource = "#client.company_dsn#" >
        SELECT
        <cfloop query = "GetFieldsOrig">
          #COLUMNNAME#
          <cfif CURRENTROW NEQ RECORDCOUNT>
            ,
          </cfif>
        </cfloop>
        FROM #RefTable#
        WHERE GUID = '#GETENTRY.GUID#'
      </cfquery>
      <cfquery name = "qryRETRIEVETEMP" datasource = "#client.company_dsn#" >
        SELECT
        <cfloop query = "GetFieldsOrig">
          #COLUMNNAME#
          <cfif CURRENTROW NEQ RECORDCOUNT>
            ,
          </cfif>
        </cfloop>
        FROM E#RefTable#M
        WHERE GUID = '#GETENTRY.GUID#' 
		<cfif #qryGET201TABLES.manytoone# eq "1">
			AND DOCNUMBER = '#GETENTRY.DOCNUMBER#'
		</cfif>
      </cfquery>
          <cfloop query = "GetFieldsOrig">
		  	<CFSET theorigstring = EVALUATE("qryRETRIEVEORIG.#COLUMNNAME#")>
			<CFSET thetempstring = EVALUATE("qryRETRIEVETEMP.#COLUMNNAME#")>
            <cfif theorigstring NEQ thetempstring>
              <cfif HEADERCHANGE>
                <tr height="20px">
                  <td><div align="center">FIELD DESCRIPTION </div></td>
                  <td><div align="center">OLD VALUE </div></td>
                  <td><div align="center">NEW VALUE </div></td>
                </tr>
              </cfif>
              <cfset headerchange = 0 >
		<tr>
                <cfif #EVALUATE("qryRETRIEVETEMP.#COLUMNNAME#")# NEQ "">
  		  <td> #UCASE(GETFIELDSORIG.COLUMNDESC)# </td>
                  <td> #EVALUATE("qryRETRIEVEORIG.#COLUMNNAME#")#
				  <CFMODULE TEMPLATE = "../../etasks/applications/201update/show201lookup.cfm" MASTERTABLE = "#qryGET201TABLES.RefTable[MY201ROW]#" MASTERFIELD = "#GETFIELDSORIG.COLUMNNAME#" VALUETOLOOK = "#EVALUATE("QRYRETRIEVEORIG.#COLUMNNAME#")#">
						#LOOKUPRESULT#				  </td>

                  <td> #EVALUATE("qryRETRIEVETEMP.#COLUMNNAME#")#
				  <CFMODULE TEMPLATE = "../../etasks/applications/201update/show201lookup.cfm" MASTERTABLE = "#qryGET201TABLES.RefTable[MY201ROW]#" MASTERFIELD = "#GETFIELDSORIG.COLUMNNAME#" VALUETOLOOK = "#EVALUATE("QRYRETRIEVETEMP.#COLUMNNAME#")#">
						#LOOKUPRESULT#				  </td>

                </cfif>
              </tr>
            </cfif>
          </cfloop>
    </CFIF>
		</table>	
  </cfoutput>
</cfif></div>

<cfif isDefined("url.docno") AND #ID# neq #client.chapa# AND APPROVED neq "Y">
	<CFQUERY NAME = "qryid" datasource="#CLIENT.COMPANY_DSN#">
		SELECT DOCNUMBER
		FROM ECIN21MAINUPDATE
		WHERE ROUTEID = '#URL.DOCNO#'
	</CFQUERY>
	<CFQUERY NAME = "qryECIN201DOCSmaster" datasource="#CLIENT.COMPANY_DSN#">
		SELECT *
		FROM ECIN201DOCS
		WHERE DOCNUMBER = '#qryid.DOCNUMBER#'
	</CFQUERY>
	<br/><br/>
	<TABLE border = "0">
		<div style="font-size:14px; color:#03C">File Attached</div>
		<cfoutput query="qryECIN201DOCSmaster">
			<tr>
				<td width ="50"><input name ="#FILENAME#" VALUE="VIEW" TYPE="BUTTON" onClick ="javascript:openMaster('#DOCCODE#','#EXTENSION#','#filename#','../../etasks/applications/201update/')"/></td>
				<td>#DOCCODE#(#filename#)</td>
			</tr>
		</cfoutput>
	</TABLE>
</cfif>


<script type="text/javascript">
	function openMaster(doccode,ext,view,ph) {
		window.open("../pre_activities/showAttacmnt.cfm?doccode=" + doccode + "&ext=" + ext + "&view=" + view +"&ph=" + ph,
					"MASTER", "width=1000,height=530,ScrollBars=Yes,Resizable=Yes,copyhistory=no");
	}
</script>













